package simplescenegraph.samples;

import java.awt.Dimension;

import javax.swing.JFrame;

import simplescenegraph.GroupNode;
import simplescenegraph.LeafNode;
import simplescenegraph.PointLight;
import simplescenegraph.SimpleSceneGraph;
import simplescenegraph.View;
import simplescenegraph.assets.models.obj.OBJModel;
import simplescenegraph.assets.models.obj.OBJModelLoader;
import simplescenegraph.math.Color4f;

public class Apple extends SimpleSceneGraph {
	
	public Apple(JFrame frame) {
		super(frame);
	}
	
	public static void main(String[] args) {
		JFrame frame = new JFrame("Apple");
		frame.setPreferredSize(new Dimension(640, 480));
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		new Apple(frame).start(100);
		frame.setVisible(true);
	}
	
	public void createScene() {
		View view = new View();
		
		view.setFov(45.0f);
		view.setNear(1);
		view.setFar(1000);
		registerView("front", view);
		view.translate(0, 0, -10);
		
		GroupNode root = getRoot();
		LeafNode appleNode, lightNode;
		
		OBJModel apple;
		apple = OBJModelLoader.load(renderer, "data/apple/apple.obj", false);
		
		appleNode = new LeafNode();
		appleNode.scale(0.03f, 0.03f, 0.03f);
		appleNode.attachSceneObject(apple);
		
		root.addChildNode(appleNode);
		
		lightNode = new LeafNode();
		
		PointLight light = new PointLight();
		light.setComponents(new Color4f[] {
				Color4f.black, Color4f.white, Color4f.white
		});
		light.setAttenuationFactors(new float[] {
				0.01f, 0.01f, 0.01f
		});
		lightNode.translate(0, 0, -5);
		lightNode.attachSceneObject(light);
		lightNode.setUserData(0);
		
		root.addChildNode(lightNode);
		
		renderer.createSkyBox("data/skybox/up.bmp",
				"data/skybox/left.bmp",
				"data/skybox/down.bmp",
				"data/skybox/right.bmp",
				"data/skybox/front.bmp",
				"data/skybox/back.bmp",
				300);
	}
	
	@Override
	public void processInput() {
	}
	
}
